<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
    xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:replace="_header_include::frag(~{::title},~{},~{})">
    <title>后台管理系统</title>
    <style>
    </style>
</head>

<body>
    <div id="maindiv" class="maindiv mainPadding" style="display: none;">
        <el-breadcrumb separator="/" class="elBreadcrumb marginB20">
            <el-breadcrumb-item>Home</el-breadcrumb-item>
            <el-breadcrumb-item>数据报表</el-breadcrumb-item>
            <el-breadcrumb-item>电销组资源接通有效率表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-row class="marginB20">
            <el-button type="primary" @click="searchYesterday">昨天</el-button>
            <el-button type="success" @click="searchWeek">近七天</el-button>
            <el-button type="warning" @click="searchMonth">本月</el-button>
            <el-button type="danger" @click="exportRs">导出Excel报表</el-button>
        </el-row>
        <div class="mainSearchBg">
            <div class="mainSearchFormBox">

                <el-form :inline="true" :model="form" class="demo-form-inline mainSearchForm" ref="form1">

                    <el-form-item label="资源类别:">
                        <el-select v-model="form.resourceId" placeholder="资源类别" style="width: 100%;" clearable
                            filterable>
                            <el-option v-for="item in resourceClassList" :key="item.id" :label="item.name"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="媒介:">
                        <el-select v-model="form.mediumId" placeholder="媒介" style="width: 100%;" clearable filterable>
                            <el-option v-for="item in mediumList" :key="item.id" :label="item.name" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="资源项目:">
                        <el-select v-model="form.resourceProjectId" placeholder="资源项目" style="width: 100%;" clearable
                            filterable>
                            <el-option v-for="item in resourceItemList" :key="item.id" :label="item.projectName"
                                :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="起止时间:">
                        <el-date-picker format="yyyy-MM-dd HH:mm" v-model="form.startTime" type="datetime"
                            placeholder="选择日期" value-format="yyyy-MM-dd HH:mm"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="—" class="widthauto">
                        <el-date-picker format="yyyy-MM-dd HH:mm" v-model="form.endTime" type="datetime"
                            placeholder="选择日期" value-format="yyyy-MM-dd HH:mm"></el-date-picker>
                    </el-form-item>
                    <el-row v-show="isShow">
                        <!-- <el-form-item label="电销分公司:">
                            <el-select v-model="teleCompanyId" placeholder="电销分公司" @change="showTele(7)"
                                style="width: 100%;" clearable filterable>
                                <el-option v-for="item in dxBusinessList" :key="item.id" :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="电销事业部:">
                            <el-select v-model="teleDeptId" placeholder="电销事业部" @change="showTele(1)"
                                style="width: 100%;" clearable filterable>
                                <el-option v-for="item in dxCauseBList" :key="item.id" :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item> -->
                        <el-form-item label="电销组:">
                            <el-select v-model="form.teleGorupId" placeholder="电销组" style="width: 100%;" clearable
                                filterable :disabled="isDisabled">
                                <el-option v-for="item in saleGroupList" :key="item.id" :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-row>
                </el-form>
                <div class="mainSearchBtnBox">
                    <el-button icon="el-icon-search" type="primary" @click="searchTable(1)" class="searchBtn">搜索
                    </el-button>
                    <span style="color: #5c6be8;cursor: pointer;margin:0 10px;" @click="toogleClick"><span
                            v-if="isShow">收起</span><span v-else>展开更多</span><i
                            :class="{'greycolor paddingL6 el-icon-arrow-up':isShow,'greycolor paddingL6 el-icon-arrow-down':!isShow}"></i></span>
                </div>
            </div>
            <el-row class="marginB20" v-loading="loading">
                <el-tabs type="card" v-model="tableActive" @tab-click="handleClick('tab')">
                    <el-tab-pane label="资源有效" name="0">
                        <el-table  ref="tableData" tooltip-effect="dark" style="width: 100%" border :data="tableData" :span-method="arraySpanMethod">
                            <el-table-column  prop="orgName" align="center" label="电销组" width="130">
                                <template slot-scope="scope">
                                  <span class="act">{{scope.row.orgName}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceCategoryName" align="center" label="资源类别" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.total == ''?scope.row.resourceCategoryName:scope.row.total}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceMediumName" align="center" label="媒介" width="80">
                            </el-table-column>
                            <el-table-column prop="projectTypeName" align="center" label="资源项目" width="80">
                            </el-table-column>
                            <el-table-column prop="issuedResources" align="center" label="下发资源量" width="80">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.issuedResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="followResources" align="center" label="跟访资源量" width="80">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.followResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="firstResources" align="center" label="首次接通资源量" width="110">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.firstResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectResources" align="center" label="接通资源量" width="80">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.connectResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="notConnectResources" align="center" label="未接通资源量" width="90">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.notConnectResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectEffectiveResources" align="center" label="接通有效资源量" width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.connectEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectNotEffectiveResources" align="center" label="接通无效资源量" width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.connectNotEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="notConnectEffectiveResources" align="center" label="未接通有效资源量" width="120">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.notConnectEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="notConnectNotEffectiveResources" align="center" label="未接通无效资源量" width="120">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.notConnectNotEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="followRate" align="center" label="跟访率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.followRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="firstRate" align="center" label="首次接通率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.firstRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="assignedConnectedRate" align="center" label="下发接通率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.assignedConnectedRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                             <el-table-column prop="assignedValidRate" align="center" label="下发有效率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.assignedValidRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceConnectRate" align="center" label="跟进接通率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.resourceConnectRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceEffectiveRate" align="center" label="跟进有效率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.resourceEffectiveRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectionRate" align="center" label="接通有效率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.connectionRate | perFormat}}</span>
                                </template>
                            </el-table-column>
                        </el-table>
                        <table-pagination :pager="pager" @change="handleClick('page')"></table-pagination>
                    </el-tab-pane>
                    <el-tab-pane label="首日资源有效" name="1">
                        <el-table  ref="tableData" tooltip-effect="dark" style="width: 100%" border :data="tableData" :span-method="arraySpanMethod">
                            <el-table-column  prop="orgName" align="center" label="电销组" width="130">
                                <template slot-scope="scope">
                                    <span class="act">{{scope.row.orgName}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceCategoryName" align="center" label="资源类别" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">
                                    {{scope.row.total == ''?scope.row.resourceCategoryName:scope.row.total}}
                                  </span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceMediumName" align="center" label="媒介" width="80">
                            </el-table-column>
                            <el-table-column prop="projectTypeName" align="center" label="资源项目" width="80">
                            </el-table-column>
                            <el-table-column prop="issuedResources" align="center" label="下发资源量" width="80">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.issuedResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="followResources" align="center" label="首日跟访资源量" width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.followResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectResources" align="center" label="首日接通资源量" width="110">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.connectResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="notConnectResources" align="center" label="首日未接通资源量" width="120">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.notConnectResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectEffectiveResources" align="center" label="首日接通有效资源量" width="140">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.connectEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectNotEffectiveResources" align="center" label="首日接通无效资源量" width="140">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.connectNotEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="notConnectEffectiveResources" align="center" label="首日未接通有效资源量" width="150">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.notConnectEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="notConnectNotEffectiveResources" align="center" label="首日未接通无效资源量" width="150">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.notConnectNotEffectiveResources}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="followRate" align="center" label="首日跟访率" :formatter="percentFormat" width="80">
                                <template slot-scope="scope">
                                    <span :class="{'act':scope.row.total != ''}">{{scope.row.followRate|perFormat}}</span>
                                </template>
                            </el-table-column>
                              <el-table-column prop="assignedConnectedRate" align="center" label="首日下发接通率" :formatter="percentFormat"  width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.assignedConnectedRate|perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="assignedValidRate" align="center" label="首日下发有效率" :formatter="percentFormat"  width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.assignedValidRate|perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceConnectRate" align="center" label="首日跟进接通率" :formatter="percentFormat"  width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.resourceConnectRate|perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="resourceEffectiveRate" align="center" label="首日跟进有效率" :formatter="percentFormat" width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.resourceEffectiveRate|perFormat}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="connectionRate" align="center" label="首日接通有效率" :formatter="percentFormat" width="110">
                                <template slot-scope="scope">
                                  <span :class="{'act':scope.row.total != ''}">{{scope.row.connectionRate|perFormat}}</span>
                                </template>
                            </el-table-column>
                        </el-table>
                        <table-pagination :pager="pager" @change="handleClick('page')"></table-pagination>
                    </el-tab-pane>
                </el-tabs>
            </el-row>
        </div>
    </div>
    <!-- import common js-->
    <div th:include="_footer_include :: #jsLib"></div>
</body>
<style>
  .act{
    font-weight: bold;
  }
  .el-pagination{
    height: 30px;
  }
</style>
<script th:inline="javascript">
    var resourceClassList = [[${clueCategoryList}]]; // 资源类别
    var mediumList = [[${mediumList}]]; //媒介
    var resourceItemList = [[${projectList}]]; //资源项目
    var saleGroupList = [[${saleGroupList}]]; //电销组
    var orgId = [[${curOrgId}]]; //电销组id

    function List() {
        this.dataStore = [];
        this.append = function (data) {
            //根据当前数组的长度插入新的数据
            this.dataStore[this.length()] = data;
        }
        this.length = function () {
            //获得数组的长度
            var length = this.dataStore.length;
            return length;
        }

        //如果找到当前的数据，就返回当前数据的下标，如果没有找到数据就返回-1
        this.find = function (data) {
            //1,获得数组的长度
            var length = this.length();
            //2,设置返回数据的下标
            var index = -1;
            //3,遍历数据
            for (var i = 0; i < length; i++) {
                if (data == this.dataStore[i]) {
                    index = i;
                    return index;
                }
            }
            return index;
        }

        this.forEach = function (call) {
            //1,获得数组的长度
            var length = this.length();
            //2,遍历数据
            for (var i = 0; i < length; i++) {
                call(this.dataStore[i]);
            }
        }

        //在before前面插入数据,如果before有数据，就插入在before前面，如果before没有数据，就把data插入到最前面的数据
        this.insertBefore = function (data, before) {
            //1，找到当前before数据的下标
            var index = this.find(before);
            var length = this.length();
            if (index == -1) {
                for (var i = length - 1; i >= 0; i--) {
                    this.dataStore[i + 1] = this.dataStore[i]
                }
                this.dataStore[0] = data;
            } else {
                for (var i = length - 1; i >= index; i--) {
                    this.dataStore[i + 1] = this.dataStore[i]
                }
                this.dataStore[index] = data;
            }
        }
    }
    var mainDivVM = new Vue({
        el: '#maindiv',
        filters: {
          perFormat (val) {
            if (!val) { // 如果没有值或值为0
                return 0 + "%";
            }
            val = (val * 1000) / 10 + "%";
            return val;
          },
        },
        data: function () {
            return {
                tableActive: 0, //tab切换
                isDisabled: false, //是否禁用电销组
                saleGroupList: saleGroupList, //电销组List
                resourceClassList: resourceClassList, //资源类别List
                mediumList: mediumList, //媒介List
                resourceItemList: resourceItemList, //资源项目
                isShow: false,
                loading: false,
                form: {
                    startTime: '',
                    endTime: '',
                    resourceId: '', //资源类别
                    mediumId: '', //媒介
                    resourceProjectId: '', //资源项目
                    teleGorupId: orgId, //电销组id
                },
                export: {
                    startTime: '',
                    endTime: '',
                    orgId: ''
                },
                tableData: [],
                pager: {
                    total: 0,
                    currentPage: 1,
                    pageSize: 20
                },
                startTimeEnd: '',
                endTimeEnd: '',
                resourceClassIdEnd: '',
                mediumIdEnd: '',
                resourceProjectIdEnd: '',
                orgIdEnd: ''
            }
        },
        methods: {
            formatTreeList(list) {
                var b = list.reduce((r, x) => ((r[x.orgId] || (r[x.orgId] = [])).push(x), r), {});
                var c = Object.keys(b).map(x => b[x]);
                var newArray = []
                for (var i = 0; i < c.length; i++) {
                    for (var j = 0; j < c[i].length; j++) {
                        for (var k = j + 1; k < c[i].length; k++) {
                            if (c[i][j].resourceCategoryName == c[i][k].resourceCategoryName) {
                                c[i][k].resourceCategoryName = ''
                                if (c[i][j].resourceMediumName == c[i][k].resourceMediumName) {
                                    c[i][k].resourceMediumName = ''
                                }
                            }
                        }
                        newArray.push(c[i][j])
                    }
                }
                return newArray
            },
            //tab、分页切换
            handleClick(type) {
                this.form.startTime = this.startTimeEnd;
                this.form.endTime = this.endTimeEnd;
                this.form.resourceId = this.resourceClassIdEnd;
                this.form.mediumId = this.mediumIdEnd;
                this.form.resourceProjectId = this.resourceProjectIdEnd;
                this.form.teleGorupId = this.orgIdEnd;
                if (type == 'tab') {
                    this.searchTable(1);
                } else {
                    this.searchTable();
                }
            },
            toogleClick() {
                this.isShow = !this.isShow
            },
            searchTable(firstPage) {
                var startTime = this.form.startTime;
                var endTime = this.form.endTime;
                if (endTime && startTime) {
                    startTime = new Date(this.form.startTime);
                    endTime = new Date(this.form.endTime);
                    if (startTime > endTime) {
                        this.$message({
                            message: '开始时间不能大于结束时间',
                            type: 'warning'
                        });
                        return;
                    }
                    var date = new Date();
                    var currentDate = moment(date).format("YYYY-MM-DD 23:59");
                    date.setMonth(date.getMonth() - 6);
                    var beforeSixMonth = moment(date).format("YYYY-MM-DD 00:00");
                    var currentDateRes = new Date(currentDate);
                    var beforeSixMonthRes = new Date(beforeSixMonth);
                    if (startTime < beforeSixMonthRes || endTime > currentDateRes) {
                        this.$message({
                            message: '请选择近6个月内的时间',
                            type: 'warning'
                        });
                        return;
                    }
                    startTime = this.limitTime(startTime, null);
                    endTime = this.limitTime(null, endTime);
                } else {
                    this.$message({
                        message: '请选择起止时间',
                        type: 'warning'
                    });
                    return;
                }

                var param = {};
                param.startTime = this.minuteFormat(startTime);
                param.endTime = this.minuteFormat(endTime);
                param.pageSize = this.pager.pageSize;
                if (firstPage) {
                    param.pageNum = firstPage;
                } else {
                    param.pageNum = this.pager.currentPage;
                }
                param.resourceCategory = this.form.resourceId;
                param.resourceMedium = this.form.mediumId;
                param.projectType = this.form.resourceProjectId;
                param.orgId = this.form.teleGorupId


                this.loading = true;
                var url = ''
                if (this.tableActive == 0) {
                    url = '/statistics/teleGroupResourceEfficiency/getResourceConectTelEfficientList'
                } else if (this.tableActive == 1) {
                    url = '/statistics/teleGroupResourceEfficiency/getFirstResourceConectTelEfficientList'
                }
                axios.post(url, param).then(function (response) {
                    if (!response) {
                        mainDivVM.loading = false;
                        mainDivVM.$message({
                            message: "接口调用失败",
                            type: 'error'
                        });
                        return;
                    }
                    var resobj = response.data;
                    if (!resobj) {
                        mainDivVM.loading = false;
                        mainDivVM.$message({
                            message: "接口调用失败",
                            type: 'error'
                        });
                        return;
                    }
                    if (resobj.code != '0') {
                        mainDivVM.loading = false;
                        mainDivVM.$message({
                            message: resobj.msg,
                            type: 'error'
                        });
                        return;
                    }else if (resobj.data && resobj.data.tableData) {
                        var resobjData = resobj.data;
                        var tableData = resobjData.tableData;
                        if( tableData.data.length && resobj.data.totalData ){
                            for (var i = 0; i < resobjData.totalData.length; i++) {
                                Vue.set(resobjData.totalData[i], 'total', '合计')
                            }
                            for (var j = 0; j < tableData.data.length; j++) {
                                Vue.set(tableData.data[j], 'total', '')
                                Vue.set(tableData.data[j], 'orgName', '')
                            }
                           
                            mainDivVM.summaryFun(resobjData.totalData, mainDivVM.formatTreeList(tableData.data))
                        }else{
                            mainDivVM.tableData = tableData.data;
                        }
        
                        mainDivVM.pager.currentPage = tableData.currentPage;
                        mainDivVM.pager.total = tableData.total;
                        mainDivVM.loading = false;

                        //重新赋值
                        mainDivVM.startTimeEnd = mainDivVM.form.startTime;
                        mainDivVM.endTimeEnd = mainDivVM.form.endTime;
                        mainDivVM.resourceClassIdEnd = mainDivVM.form.resourceId;
                        mainDivVM.mediumIdEnd = mainDivVM.form.mediumId;
                        mainDivVM.resourceProjectIdEnd = mainDivVM.form.resourceProjectId;
                        mainDivVM.orgIdEnd = mainDivVM.form.teleGorupId
                    } else {
                        mainDivVM.loading = false;
                        mainDivVM.startTimeEnd = mainDivVM.form.startTime;
                        mainDivVM.endTimeEnd = mainDivVM.form.endTime;
                        mainDivVM.resourceClassIdEnd = mainDivVM.form.resourceId;
                        mainDivVM.mediumIdEnd = mainDivVM.form.mediumId;
                        mainDivVM.resourceProjectIdEnd = mainDivVM.form.resourceProjectId;
                        mainDivVM.orgIdEnd = mainDivVM.form.teleGorupId
                    }
                }).catch(function (error) {
                    mainDivVM.loading = false;
                    mainDivVM.$message({
                        message: "请求失败，请稍后重试",
                        type: "error"
                    });
                    mainDivVM.startTimeEnd = mainDivVM.form.startTime;
                    mainDivVM.endTimeEnd = mainDivVM.form.endTime;
                    mainDivVM.resourceClassIdEnd = mainDivVM.form.resourceId;
                    mainDivVM.mediumIdEnd = mainDivVM.form.mediumId;
                    mainDivVM.resourceProjectIdEnd = mainDivVM.form.resourceProjectId;
                    mainDivVM.orgIdEnd = mainDivVM.form.teleGorupId
                });
            },
            limitTime(start, end) {
                var startTime = this.minuteFormat(start);
                var endTime = this.minuteFormat(end);
                var date = new Date();
                data = this.minuteFormat(date); // 现在的时间
                data = data.slice(0, 8);
                if (startTime) {
                    var s = startTime.slice(0, 8);
                    if (s < data) {
                        this.form.startTime = moment(start).format("YYYY-MM-DD 00:00");
                        return this.form.startTime;
                    }
                    return start;
                }
                if (endTime) {
                    var e = endTime.slice(0, 8);
                    if (e < data) {
                        this.form.endTime = moment(end).format("YYYY-MM-DD 23:59");
                        return this.form.endTime;
                    }
                    return end;
                }
            },
            arraySpanMethod({
                row,
                column,
                rowIndex,
                columnIndex
            }) { // 合并第一行
                if (row.total && row.total == '合计') {
                    if (columnIndex === 1) {
                        return [1, 3]
                    } else if (columnIndex === 2) {
                        return [0, 0]
                    } else if (columnIndex === 3) {
                        return [0, 0]
                    }
                }

            },

            indexFun(index) { // 表格序号
                return index;
            },
            minuteFormat(m) {
                if (!m) {
                    return "";
                }
                var timeStr = new Date(m);
                var yearRes = timeStr.getFullYear()
                var monthRea = timeStr.getMonth() + 1;
                monthRea = monthRea < 10 ? "0" + monthRea : monthRea;
                var dateRes = timeStr.getDate();
                dateRes = dateRes < 10 ? "0" + dateRes : dateRes;
                var hoursRes = timeStr.getHours();
                hoursRes = hoursRes < 10 ? "0" + hoursRes : hoursRes;
                var minRes = timeStr.getMinutes();
                minRes = minRes < 10 ? "0" + minRes : minRes;
                var timeRes = "" + yearRes + monthRea + dateRes + hoursRes + minRes;
                return timeRes;
            },
            //根据id将合计插入对应id上边
            summaryFun(totalData, tableData) {
                var list = new List();
                for (var i = 0; i < tableData.length; i++) {
                    list.append(tableData[i]);
                }
                for (var i = 0; i < totalData.length; i++) {
                    for (var j = 0; j < tableData.length; j++) {
                        if (totalData[i].orgId == tableData[j].orgId) {
                            list.insertBefore(totalData[i], tableData[j])
                        }
                    }
                }
                var arr = []
                list.forEach(function (data) {
                    arr.push(data)
                });
                mainDivVM.tableData = this.repeatArr(arr)
            },
            //去重
            repeatArr(arr) {
                var x = new Set(arr);
                return [...x];
            },
            //白分比格式话
            percentFormat(row, column) {
                var percent = row[column.property];
                if (!percent) { // 如果没有值或值为0
                    return 0 + "%";
                }
                percent = (percent * 1000) / 10 + "%";
                return percent;
            },
            timeFormat(row, column) { // 时间格式化：时分秒
                var time = row[column.property];
                var timeResult = this.timeFun(time);
                return timeResult;
            },
            timeFun(s) {
                var t = "";
                var hour = Math.floor(s / 3600);
                var min = Math.floor(s / 60) % 60;
                var sec = s % 60;
                if (hour < 10) {
                    t += "0";
                }
                t += hour + "时"
                if (min < 10) {
                    t += "0";
                }
                t += min + "分";
                if (sec < 10) {
                    t += "0";
                }
                t += sec + "秒";
                return t;
            },
            searchYesterday() { // 昨天
                var today = new Date();
                today.setTime(today.getTime() - 24 * 60 * 60 * 1000);
                var startTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() +
                    " 00:00";
                var endTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() +
                    " 23:59";
                this.form.startTime = startTime;
                this.form.endTime = endTime;
                this.searchTable(1);
            },
            searchWeek() { // 近七天
                var a = new Date();
                var year = a.getFullYear();
                var month = a.getMonth();
                var date = a.getDate();
                var b = new Date(year, month, date);
                var c = b.valueOf() - 6 * 24 * 60 * 60 * 1000;
                var d = b.valueOf();
                var startTime = new Date(c);
                var endTime = new Date(d);
                this.form.startTime = startTime.getFullYear() + "-" + (startTime.getMonth() + 1) + "-" +
                    startTime.getDate() + " 00:00";
                this.form.endTime = endTime.getFullYear() + "-" + (endTime.getMonth() + 1) + "-" + endTime
                    .getDate() + " 23:59";
                this.searchTable(1);
            },
            searchMonth() { // 本月 
                var a = new Date();
                var year = a.getFullYear();
                var month = a.getMonth();
                var date = a.getDate();
                var b = new Date(year, month, date);
                var f = new Date(year, month, 01);
                var c = f.valueOf();
                var startTime = new Date(c);
                this.form.startTime = startTime.getFullYear() + "-" + (startTime.getMonth() + 1) + "-" +
                    startTime.getDate() + " 00:00";
                this.form.endTime = year + "-" + (month + 1) + "-" + date + " 23:59";
                this.searchTable(1);
            },
            //导出
            exportRs() {
                var param = {};
                param.startTime = this.minuteFormat(this.startTimeEnd);
                param.endTime = this.minuteFormat(this.endTimeEnd);
                param.resourceCategory = this.resourceClassIdEnd;
                param.resourceMedium = this.mediumIdEnd;
                param.projectType = this.resourceProjectIdEnd;
                param.orgId = this.orgIdEnd

                axios.post('/statistics/teleGroupResourceEfficiency/exportResourceTelEfficiency', param, {
                        responseType: 'blob'
                    })
                    .then(function (response) {
                        var data = response.data;
                        var fileName = response.headers.filename;
                        saveAs(data, decodeURI(fileName));
                    })
                    .catch(function (error) {
                        mainDivVM.$message({
                            message: "导出失败，请稍后重试",
                            type: "error"
                        });
                    });
            }
        },
        created() {
            // 默认进入显示当天时间
            var today = new Date();
            today.setTime(today.getTime());
            var startTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() +
                " 00:00";
            var endTime = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " 23:59";
            if (orgId) {
                this.isDisabled = true;
            }
            this.form.startTime = startTime;
            this.form.endTime = endTime;
            this.startTimeEnd = this.form.startTime;
            this.endTimeEnd = this.form.endTime;
            var localVal=localStorage.getItem('allChangePageSize')?parseInt(localStorage.getItem('allChangePageSize')):'';
            if(localVal){this.pager.pageSize = localVal;}
            this.searchTable();
        },
        mounted() {
            document.getElementById('maindiv').style.display = 'block';
        }
    })
</script>

</html>